#include "qsizeproperty.h"

#include "qintproperty.h"

#include "../../libs/sharedLib/qeditorlabel.h"

QSizeProperty::QSizeProperty(SHAREDLIB::QAbstractProperty *parent):
    SHAREDLIB::QAbstractProperty(parent)
{
    m_width=new QIntProperty(this);
    m_width->setAttribute("property_name","Width");
    m_width->setAttribute("name","Width");

    m_height=new QIntProperty(this);
    m_height->setAttribute("property_name","Height");
    m_height->setAttribute("name","Height");
}

QWidget* QSizeProperty::getEditor()
{
    if(attribute("editabled").toBool())
    {
        m_editor=new SHAREDLIB::QEditorLabel(this);
    }
    return QAbstractProperty::getEditor();
}

void QSizeProperty::setValue(const QVariant &value)
{
    QSize sz=value.toSize();

    m_width->setValue(sz.width());
    m_height->setValue(sz.height());

    SHAREDLIB::QAbstractProperty::setValue(value);
}

void QSizeProperty::subPropertyChanged(const QVariant &)
{
    QSize sz;
    sz.setWidth(m_width->getValue().toInt());
    sz.setHeight(m_height->getValue().toInt());
    setValue(sz);
}

QString QSizeProperty::valueText()
{
    return QString("%1 x %2").arg(m_width->getValue().toInt()).arg(m_height->getValue().toInt());
}
